package com.example.student.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.student.R;
import com.example.student.bean.SubjectBean;

import java.util.List;

/**
 * Created by Administrator on 2017/9/6.
 */

public class SubjectAdapter extends BaseAdapter {

    private List<SubjectBean> list;
    private Context context;

    public SubjectAdapter(Context context, List<SubjectBean> lists) {
        this.context = context;
        this.list = lists;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent) {
        TextView bank = null;
        if (converView == null) {
            converView = View.inflate(context, R.layout.item_subject, null);
            bank = (TextView) converView.findViewById(R.id.name);
            converView.setTag(bank);
        } else {
            bank = (TextView) converView.getTag();
        }
        String name = list.get(position).getName();
        if (!TextUtils.isEmpty(name)) {
            bank.setText(name);
        }

        return converView;
    }
}
